package io.renren.modules.sys.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import io.renren.modules.sys.shiro.ShiroUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;

import io.renren.modules.sys.entity.ContainerEntity;
import io.renren.modules.sys.entity.CustominfoEntity;
import io.renren.modules.sys.service.CustominfoService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;

/**
 * 
 *
 * @author chenshun
 * @email sunlightcs@gmail.com
 * @date 2019-11-20 22:43:10
 */
@RestController
@RequestMapping("/sys/custominfo")
public class CustominfoController {
	@Autowired
	private CustominfoService custominfoService;

	/**
	 * 列表
	 */
	@RequestMapping("/list")
	@RequiresPermissions("sys:custominfo:list")
	public R list(@RequestParam Map<String, Object> params) {
		PageUtils page = custominfoService.queryPage(params);

		return R.ok().put("page", page);
	}

	/**
	 * 信息
	 */
	@RequestMapping("/info/{number}")
	@RequiresPermissions("sys:custominfo:info")
	public R info(@PathVariable("number") String number) {
		System.err.println("number=" + number);
		CustominfoEntity custominfo = custominfoService.selectById(number);
		if (custominfo != null) {
			return R.ok().put("custominfo", custominfo);
		} else {
			return R.error(200, "用户编号不存在");
		}
	}

	@RequestMapping("/info2/{customnumber}")
	@RequiresPermissions("sys:custominfo:info")
	public R info2(@PathVariable("customnumber") String customnumber) {
		System.err.println("customnumber=" + customnumber);
		Wrapper<CustominfoEntity> wrapper = new EntityWrapper<CustominfoEntity>();
		// QueryWrapper<ContainerEntity> queryWrapper = new QueryWrapper<>();
		// wrapper = new Condition();
		wrapper.eq("customnumber", customnumber);
		//List<CustominfoEntity> containerList = custominfoService.selectList(wrapper);
		CustominfoEntity custominfo = custominfoService.selectOne(wrapper);
		if (custominfo != null) {
			return R.ok().put("custominfo", custominfo);
		} else {
			return R.error(200, "用户编号不存在");
		}
	}

	/**
	 * 保存
	 */
	@RequestMapping("/save")
	@RequiresPermissions("sys:custominfo:save")
	public R save(@RequestBody CustominfoEntity custominfo) {
		custominfo.setDeptId(ShiroUtils.getUserEntity().getDeptId());
		custominfoService.insert(custominfo);

		return R.ok();
	}

	/**
	 * 修改
	 */
	@RequestMapping("/update")
	@RequiresPermissions("sys:custominfo:update")
	public R update(@RequestBody CustominfoEntity custominfo) {
		custominfoService.updateById(custominfo);

		return R.ok();
	}

	/**
	 * 删除
	 */
	@RequestMapping("/delete")
	@RequiresPermissions("sys:custominfo:delete")
	public R delete(@RequestBody String[] numbers) {
		custominfoService.deleteBatchIds(Arrays.asList(numbers));

		return R.ok();
	}

}
